package com.sensePlusVR.bean;

import android.content.Context;

import com.sensePlusVR.application.VRApplication;
import com.sensePlusVR.base.EntityBase;
import com.sensePlusVR.utils.Constant;
import com.sensePlusVR.utils.MyLog;

import org.xutils.DbManager;
import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;
import org.xutils.db.sqlite.WhereBuilder;

import java.util.Arrays;
import java.util.List;

@Table(name = "BuriePointEventReqDto")
public class BuriePointEventReqDto extends EntityBase{
	private static final String TAG = BuriePointEventReqDto.class.getSimpleName();
	
	
	
	@Column(name = "uid")
	private Integer uid;

	@Column(name = "uuid")
	private String uuid;

	@Column(name = "provider")
	private String provider = "LOVERS";

	@Column(name = "location")
	private Double[] location;

	@Column(name = "event")
	private String event;

	@Column(name = "last_event")
	private String last_event;

	@Column(name = "duration")
	private Long duration;

	@Column(name = "data")
	private String data;

	@Column(name = "remark")
	private String remark;

	@Column(name = "event_time")
	private String event_time;
	
	@Column(name = "mode")
	private String mode;//访问模式 Debug Prod(241为Debug,其他为Prod)
	
	@Column(name = "flag")
	private Integer flag;//访问标记-1 取消  0：Fail 1：Success
	
	//非服务器需要字段
	
	@Column(name = "clcItemId")
	private Integer clcItemId;//统计下载事件需要标记
	
	@Column(name = "start_time")
	private Long start_time;
	
	@Column(name = "end_time")
	private Long end_time;
	
	public BuriePointEventReqDto() {
		super();
	}

	
	public BuriePointEventReqDto(Integer uid, String provider, String event,
			Long duration, String data, String event_time, String mode,
			Integer flag) {
		super();
		this.uid = uid;
		this.provider = provider;
		this.event = event;
		this.duration = duration;
		this.data = data;
		this.event_time = event_time;
		this.mode = mode;
		this.flag = flag;
	}


	public Integer getUid() {
		return uid;
	}

	public void setUid(Integer uid) {
		this.uid = uid;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getProvider() {
		return provider;
	}

	public void setProvider(String provider) {
		this.provider = provider;
	}

	public Double[] getLocation() {
		return location;
	}

	public void setLocation(Double[] location) {
		this.location = location;
	}

	public String getEvent() {
		return event;
	}

	public void setEvent(String event) {
		this.event = event;
	}

	public String getLast_event() {
		return last_event;
	}

	public void setLast_event(String last_event) {
		this.last_event = last_event;
	}

	public Long getDuration() {
		return duration;
	}

	public void setDuration(Long duration) {
		this.duration = duration;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getEvent_time() {
		return event_time;
	}

	public void setEvent_time(String event_time) {
		this.event_time = event_time;
	}

	public String getMode() {
		return mode;
	}

	public void setMode(String mode) {
		this.mode = mode;
	}

	public Integer getFlag() {
		return flag;
	}

	public void setFlag(Integer flag) {
		this.flag = flag;
	}
	
	public Integer getClcItemId() {
		return clcItemId;
	}


	public void setClcItemId(Integer clcItemId) {
		this.clcItemId = clcItemId;
	}

	

	public Long getStart_time() {
		return start_time;
	}


	public void setStart_time(Long start_time) {
		this.start_time = start_time;
	}

	

	public Long getEnd_time() {
		return end_time;
	}


	public void setEnd_time(Long end_time) {
		this.end_time = end_time;
	}


	@Override
	public String toString() {
		return "BuriePointEventReqDto [uid=" + uid + ", uuid=" + uuid
				+ ", provider=" + provider + ", location="
				+ Arrays.toString(location) + ", event=" + event
				+ ", last_event=" + last_event + ", duration=" + duration
				+ ", data=" + data + ", remark=" + remark + ", event_time="
				+ event_time + ", mode=" + mode + ", flag=" + flag
				+ ", clcItemId=" + clcItemId + ", start_time=" + start_time
				+ ", end_time=" + end_time + "]";
	}
	
	
	public static void saveOrUpdate(Object object) {
		try {
			Context context = VRApplication.getAppContext();
			if (context != null) {
				DbManager db = VRApplication.getDbManager();
				db.saveOrUpdate(object);
			}
		} catch (Exception e) {
			MyLog.e(TAG, "saveOrUpdate failed: " + e);
		}
	}
	
	public static List<BuriePointEventReqDto> getAllSuccessBuriePointEventReqDto(){
		try {
			Context context = VRApplication.getAppContext();
			if (context != null) {
				DbManager db = VRApplication.getDbManager();
				return db.selector(BuriePointEventReqDto.class).where("flag", "=", Constant.BURIED_FLAG_SUCCESS).findAll();
			}
		} catch (Exception e) {
			MyLog.e(TAG, "getAllBuriePointEventReqDto failed: " + e);
			return null;
		}
		return null;
	}
	
	public static void delItem(BuriePointEventReqDto buriePointEventReqDto){
		try {
			Context context = VRApplication.getAppContext();
			if (context != null) {
				DbManager db = VRApplication.getDbManager();
				db.delete(buriePointEventReqDto);
			}
		} catch (Exception e) {
			MyLog.e(TAG, "delItem failed: " + e);
		}
		
	}
	
	public static void delAllSuccessData(){
		try {
			Context context = VRApplication.getAppContext();
			if (context != null) {
				DbManager db = VRApplication.getDbManager();
				db.delete(BuriePointEventReqDto.class, WhereBuilder.b("flag", "=", Constant.BURIED_FLAG_SUCCESS));
			}
		} catch (Exception e) {
			MyLog.e(TAG, "delAllData failed: " + e);
		}
		
	}
	
	public static BuriePointEventReqDto getBuriePointByClcItemId(Integer clcItemId){
		try {
		Context context = VRApplication.getAppContext();
		if(context != null){
			DbManager db = VRApplication.getDbManager();
			return db.selector(BuriePointEventReqDto.class).where("clcItemId", "=", clcItemId).findFirst();
		}
		} catch (Exception e) {
			MyLog.e(TAG, "getBuriePointByClcItemId failed: " + e);
			return null;
		}
		return null;
	}
	
	
}
